package cn.com.connext.scrm.service;

import cn.com.connext.scrm.domain.master.*;
import cn.com.connext.scrm.repository.master.DwaConvertCodeRepository;
import cn.com.connext.scrm.repository.master.DwaGetCouponRepository;
import cn.com.connext.scrm.repository.master.DwaQuestionRecordRepository;
import cn.com.connext.scrm.repository.master.PrizeRepository;
import cn.com.connext.scrm.service.dto.JsonResult;
import cn.com.connext.scrm.service.mapper.TmpMsgRecordService;
import cn.com.connext.scrm.web.rest.req.ProduceReq;
import cn.com.connext.scrm.web.rest.vm.DwaIsReceiveVM;
import cn.com.connext.scrm.web.rest.vm.DwaQuestionRecordVM;
import cn.com.connext.scrm.web.rest.vm.TempSubScribeVm;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class DwaQuestionRecordService {
    @Autowired
    private DwaQuestionRecordRepository dwaQuestionRecordRepository;

    public DwaQuestionRecord findQuestionByUnionId(String unionId) {
       return dwaQuestionRecordRepository.findQuestionByUnionId(unionId);
    }

    public JsonResult save(DwaQuestionRecordVM vm) {
        JsonResult result =new JsonResult();
        if(vm !=null){
            DwaQuestionRecord record =new DwaQuestionRecord();
            if(vm.getQuestionId() !=null){
                record.setQuestionId(vm.getQuestionId());
            }else{
                result.setMessage("quesionId不能为空！");
                result.setState(-1);
                return result;
            }
            if(StringUtils.isNotEmpty(vm.getUnionId())){
                record.setUnionId(vm.getUnionId());
            }else{
                result.setMessage("unionId不能为空！");
                result.setState(-1);
                return result;
            }
            record.setCreateTime(ZonedDateTime.now());
            dwaQuestionRecordRepository.save(record);
            result.setState(0);
            result.setMessage("添加成功");
        }
        return result;
    }
}
